import logging
import cv2
import os

def main(input_folder: str, output_folder: str):
    if not os.path.exists(input_folder) :
        print("输入目录不存在")
        exit()
    if not os.path.exists(output_folder) :
        print("输出目录不存在")
        os.makedirs(output_folder)

    print("begin")
    for filename in os.listdir(input_folder) :
        input_file = os.path.join(input_folder, filename)
        print(f"扫描文件 {input_file}")
        if filename.lower().endswith(('.png', '.bmp', '.jfif', '.tiff', '.jpg', '.jpeg', '.webp')) :
            image  = cv2.imread(input_file)
            output_file = os.path.join(output_folder, os.path.splitext(filename)[0] + '.jpeg')
            cv2.imwrite(output_file, image, [int(cv2.IMWRITE_JPEG_QUALITY), 90])
            print(f"{input_file} - {output_file}")

if __name__ == "__main__" :
    main("./image", "./image-jpeg")
